﻿<%@ Page Title="Frontdesk - User Administration" Language="C#" MasterPageFile="~/Views/Shared/Frontdesk.Master"
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<Sendz.Domain.User>>" %>

<asp:Content ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <% if (Model.Count() == 0)
       { %>
    <h2 class="title">
        Got Users...?</h2>
    <div class="create">
        <div class="create-link">
            <%: Html.ActionLink("Create a User!", "CreateUser", null, new { @title = "Create a new Frontdesk user" }) %></div>
    </div>
    <p class="justify clear">
        You don't have any users created (uh, so how are you here)?!
        <%: Html.ActionLink("Click here to add a user!", "Create", null, new { @title = "Create a new Frontdesk user" })%></p>
    <% }
       else
       { %>
    <h2 class="title">
        Frontdesk Users</h2>
    <div class="create">
        <div class="create-link">
            <%: Html.ActionLink("Create a User!", "CreateUser", null, new { @title = "Create a new Frontdesk user" }) %></div>
    </div>
    <p class="justify clear">
        Click on any user's name to edit their account, or click on the 'Actions' link below
        to see all the choices at your disposal.</p>
    <p class="justify-right clear caption">
        [<%: Html.ActionLink("Sort by Last Login", "ListUsers", new { SortBy = "LastLogin" }, new { title = "Sort users by the date of their last login, descending" })%>]&nbsp;[<%: Html.ActionLink("Sort by Lastname, Firstname", "ListUsers", null, new { title = "Sort users by their last name followed by their first name, ascending" }) %>]
    </p>
    <div class="list">
        <% foreach (var user in Model)
           {%>
        <div class="list-item">
            <div class="list-item-link">
                <% var concatUserInfo = (!string.IsNullOrEmpty(user.Lastname) && !string.IsNullOrEmpty(user.Firstname)) ? user.Lastname + ", " + user.Firstname + " (" + user.Email + ")" : user.Email;
                   var lastLogin = (user.LastLogin == null) ? "(Never)" : user.LastLogin.ToString(); %>
                <%: Html.ActionLink(concatUserInfo, "EditUser", new { id = user.UserKey }, new { @class = "inline-message", title = "This user last logged in at: " + lastLogin + "; " + user.ResponsesRemaining + " responses remaining, " + user.InvitesRemaining + " invites remaining" }) %>
            </div>
            <div class="menu">
                <span class="actions" title="Click to display the actions you can use for this user">
                    Actions&nbsp;<img src="<%= Url.Content("~/Content/Frontdesk/dropdown.gif") %>" alt="View options" /></span>
                <ul class="nav">
                    <li>
                        <%: Html.ActionLink("Login as this User", "LoginAs", "Account", new { id = user.UserKey, adminKey = ViewData["AdminKey"] }, new { title = "Close your session and login as this user to see what they see" })%></li>
                    <li>
                        <%: Html.ActionLink("Edit", "EditUser", new { id = user.UserKey }, new { title = "Edit this user" })%></li>
                    <li>
                        <%: Html.ActionLink("Reset Password", "ResetUserPassword", new { id = user.UserKey }, new { title = "Reset the user's password and send them a confirmation email with the new password" })%></li>
                    <li>
                        <%: Html.ActionLink("Resend Invite", "ResendInvite", new { id = user.UserKey }, new { title = "Resend this user's invitation email", @class = "modal" })%></li>
                    <li>
                        <%: Html.ActionLink("Remove", "RemoveUser", new { id = user.UserKey }, new { title = "Remove this user", onclick = "return confirm('Are you sure? Removing a user will inactivate their account and make all data inaccessible to them!');" })%></li>
                </ul>
            </div>
        </div>
        <%
            }%>
    </div>
    <% } %>
</asp:Content>
<asp:Content ContentPlaceHolderID="Sidebar" runat="server">
    <% Html.RenderPartial("videohelp"); %>
</asp:Content>
<asp:Content ContentPlaceHolderID="footer" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $("div.menu span").click(function () {
                $(this).parent().find("ul.nav").slideDown('fast').show(); // Drop down the subnav on click
                $(this).parent().hover(function () { }, function () {
                    $(this).parent().find("ul.nav").slideUp(); // When the mouse hovers out of the subnav, move it back up
                });
            });
        });
    </script>
</asp:Content>
